var app = getApp();
const utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: "",
    startDate: 0,
    pid: 0,
    pageurl: ""
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var staffid = options.staffid;
    if (staffid) {
      wx.setStorageSync('staffid', staffid);
    }
    that.setData({
      pageurl: options.url
    })
    if (options.url == "productDetails.html") {
      that.setData({
        startDate: utils.formatTime(new Date())
      });
      that.comanToWebUrl(options);
    } else {
      that.toWebUrl(options);
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    if (this.data.pageurl == "productDetails.html") {
      utils.recordActionTime(this.data.startDate, 22, this.data.pid)
    }
  },

  onUnload: function () {
    if (this.data.pageurl == "productDetails.html") {
      utils.recordActionTime(this.data.startDate, 22, this.data.pid)
    }
  },

  //不限制跳转
  comanToWebUrl(options) {
    var url = options.url;
    var pid = 0,
      seltoid = 0,
      name = "";
    if (options.pid) {
      pid = options.pid;
      this.setData({
        pid: pid
      })
    }
    if (options.seltoid) {
      seltoid = options.seltoid;
    }
    if (options.name) {
      name = options.name;
    }
    var cardId = wx.getStorageSync("cardId");
    var uid = app.globalData.userInfo.Uid;
    var storeid = app.globalData.storeId;
    this.setData({
      url: app.globalData.webhost + url + "?pid=" + pid + "&showbtn=1" + "&seltoid=" + seltoid + "&name=" + encodeURIComponent(name) + "&storeid=" + storeid + "&uid=" + uid + "&staffId=" + cardId + "&storeAppId=" + app.globalData.storeAppId
    })
  },

  //网页跳转
  toWebUrl: function (options) {
    var url = options.url;
    let staffid = wx.getStorageSync('cardId');
    if (!staffid) {
      staffid = 0;
    }
    var uid = app.globalData.userInfo.Uid;
    if (options.uid) {
      uid = options.uid;
    }
    var storeid = app.globalData.storeId;
    var param = "ssologin.html?staffid=" + staffid + "&uid=" + uid + "&storeid=" + storeid + "&url=" + url;
    switch (url) {
      case "bossRadarIndex.html":
        this.setData({
          url: app.globalData.webhost + param
        })
        break;
      case "myself.html":
        this.setData({
          url: app.globalData.webhost + param + '?rand=0508'
        })
        break;
      case "myCard.html":
        this.setData({
          url: app.globalData.webhost + param
        })
        break;
      case "contactPerson.html":
        this.setData({
          url: app.globalData.webhost + param + '?rand=' + Math.random()
        })
        break;
      case "friendState.html":
        this.setData({
          url: app.globalData.webhost + param
        })
        break;
      case "myProductList.html":
        this.setData({
          url: app.globalData.webhost + param
        })
        break;
      case "message_list.html":
        this.setData({
          url: app.globalData.webhost2 + 'plugins/webim/' + url + "?&uid=" + uid
        });
        break;
      case "wechat":
        this.setData({
          url: 'https://mp.weixin.qq.com/s/Q2Gt-ggdYpWZ9-pm6G_tbQ'
        });
        break;
      case "mysign.html":
        this.setData({
          url: app.globalData.webhost + param
        });
        break;
      case "mylabel.html":
        this.setData({
          url: app.globalData.webhost + param
        });
        break;
      case "myApplyAgency.html":
        this.setData({
          url: app.globalData.webhost + param
        });
        break;
      case "customerDetail.html":
        this.setData({
          url: app.globalData.webhost + param + '?' + options.urlparam
        });
        break;
      case "card-export.html":
        this.setData({
          url: app.globalData.webhost + param + '?' + options.urlparam
        });
        break;  
      case "setAccount.html":
        this.setData({
          url: app.globalData.webhost + param
        });
        break;
      case "sessionDetail.html":
        this.setData({
          url: app.globalData.webhost3 + url + '?' + decodeURIComponent(options.chatparam)
        })
        break;
      case "chatMessageList.html":
        this.setData({
          url: app.globalData.webhost3 + url + '?' + decodeURIComponent(options.chatparam)
        });
        break;
      case "serviceAgreement.html":
        this.setData({
          url: app.globalData.webhost + url + '?uid=' + uid
        });
        break;     
      case "jiujiuCardDesc.html":
        this.setData({
          url: app.globalData.webhost + url + '?type=' + options.type
        });
        break;
      case "flyerRulesBossPay.html":
        this.setData({
          url: app.globalData.webhost + url + '?rand=0508'
        });
        break;
      case "flyerRulesMerSend.html":
        this.setData({
          url: app.globalData.webhost + url + '?rand=0508'
        });
        break;
      default:
        this.setData({
          url: decodeURIComponent(url)
        })
        break;
    }
  }
})